<?php
//App::uses('AppController', 'Controller');

class NotifiController extends AppController {

    public $name = 'Notifi';
	public $uses = array('tbl_log');

	public function all() {

        if(!empty($this->data['notice'])) {
            $msg = $this->data['notice']['msg'];
            if(!empty($msg)) {
                App::uses('HttpSocket', 'Network/Http');
                $HttpSocket = new HttpSocket();

                $url = $this->server_url . '/notice_all';
                $data = 'msg='.$msg;

                $result = json_decode($HttpSocket->post($url, $data), true);

                if($result['rcode'] == 0) {
                    $this->Session->setFlash('공지 전송 완료', 'default', array('class' => 'success'), 'good');
                    $result_info = '공지 전송 완료';
                } else {
                    $this->Session->setFlash('전송 실패!! 인터넷 상태를 확인하세요.', 'default', array('class' => 'message'), 'bad');
                    $result_info = '공지 전송 실패!!';
                }

                //로그 설정
                $logdata = array("client_ip"=>$_SERVER['REMOTE_ADDR'],"date:"=>date('Y-m-d H:i:s',time()),'operation_info'=>$url,'operation_data'=>$data,'operation_result'=>$result_info);
                $this->tbl_log->save($logdata);
            }
        }

        $this->set(compact(array()));
	}
}
